import {searchPage, deleteById, searchColors, searchBrands, searchTypes} from '../../api/brand'
import {
    deleteProductById,
    addProduct,
    editProduct,
    searchGoodsVo,
    addGoods,
    addSecondGoods,
    searchGoodsbrandCri,
    deleteBrandById,
    addBrand,
    editBrand,
    GoodstypeCri
} from '../../api/product'
import pickerOptions from '@/utils/date';
// import {getBase64Str} from '../../utils/base64Utils'
// import base64 from '../../utils/getbase64Str2';


let goodbrand = {
    data() {
        return {
            //日期组件
            pickerOptions: pickerOptions,
            //table的list
            tableData: [],
            goodsData: [],
            goodsParams: {
                currentPage: 1,
                pageSize: 2
            },
            goodsTotal: 0,
            total: 0,
            searchParams: {
                currentPage: 1,
                pageSize: 4
            },
            dialogVisible: false,
            innerVisible: false,
            dialogVisibleEdit: false,
            dialogVisibleAddFirst: false,
            dialogVisibleAddSecond: false,
            showGoods: false,
            secondGoodsData: {},
            formData: {},
            formDataEdit: {},
            deleteForm: {},
            editForm: {},
            pickForm: {},
            goods: {},
            products: {},
            details: {},
            addFirstProducts: {},
            imageUrl: '',
            formLabelWidth: '120px',
            colorList: [],
            brandList: [],
            typeList: []
        };
    },
    methods: {
        addSecondGoods() {
            addSecondGoods(this.secondGoodsData);
        },
        //复选框的change事件，删除和修改拿到id

        checkBoxSelectionChange() {

        },
        currentPageChange(currentPage) {
            //console.log(currentPage);
            this.searchParams.currentPage = currentPage;
            this.searchGoodsbrand();
        },
        currentPageChange1(currentPage) {
            //console.log(currentPage);
            this.goodsParams.currentPage = currentPage;
            this.findGoods();
        },
        async findPage() {
            let response = await searchPage(this.searchParams);

            this.total = response.total;

            console.log(" response.data:", response.data);
            this.tableData = response.data;
        },
        async findGoods() {
            let response = await searchGoodsVo(this.goodsParams);

            this.goodsTotal = response.total;

            console.log(" goods.data:", response.data);
            console.log(" goodsparam.data:", this.goodsParams);
            this.goodsData = response.data;
        },
        resetGoodsForm() {
            this.goodsParams = {currentPage: 1, pageSize: 2};

            this.findGoods();
        },
        async init() {
            let response1 = await searchColors();
            let response2 = await searchBrands();
            let response3 = await searchTypes();
            console.log("this.brandList:", this.brandList)
            this.colorList = response1;
            this.brandList = response2;
            this.typeList = response3;
        },
        chooseTime() {
            this.searchParams.startTime = this.pickerOptions.startArrayDate[0];
            this.searchParams.endTime = this.pickerOptions.startArrayDate[1];
        },
        resetForm() {
            this.searchParams = {currentPage: 1, pageSize: 2};
            this.pickerOptions.startArrayDate = '';
            this.findPage();
        },
        //async表示异步调用 await：表示执行完这条语句，才执行下面语句
        async deleteById() {
            await deleteById(this.formData.id);
            this.findPage();
        },

        async deleteProductById() {
            await deleteBrandById(this.deleteForm.brandId);
            console.log("deleteForm.goodId:", this.deleteForm.goodId);
            this.searchGoodsbrand();
        },
        getImgStr(e) {
            base64.getbase64Str(e.file).then(response => {
                this.formData.brandLogo = response;
                this.imageUrl = response;
            })

        },
        async addOrEdit() {
            await addBrand(this.goods);
            this.goods = {};
            this.searchGoodsbrand();
        },
        async productEdit() {
            await editBrand(this.formDataEdit);
            this.formDataEdit = {};

            this.searchGoodsbrand();
        },
        initProduct(row) {
            console.log("brandEdit",row);
            this.formDataEdit = JSON.parse(JSON.stringify(row))
            console.log(" this.goods brandEdit:", this.goods);
        },
        pickProduct(row) {
            this.products = row;
        },
        productAddFirst() {
            this.addFirstProducts.goodProductid = this.products.productId;
            this.addFirstProducts.goodName = this.products.goodName;
            this.addFirstProducts.goodMarketprice = this.products.goodMarketprice;
            this.addFirstProducts.goodMallprice = this.products.goodMallprice;
            this.addFirstProducts.goodMinstorage = this.products.goodMinstorage;
            addGoods(this.addFirstProducts);
            this.addFirstProducts = {};
            this.findGoods();
        },
        showGoodsDetails(row) {
            this.details = row;
        },
        async searchGoodsbrand() {
            let response = await searchGoodsbrandCri(this.searchParams);
            console.log("searchGoodsbrand:", this.searchParams);
            this.brandList = response.data;
            this.total = response.total;
        }
    },
    created() {
        // this.findPage();
        // this.findGoods();
        // this.init();
        this.searchGoodsbrand();
    }
};

export default goodbrand;